package week1;

import java.lang.reflect.Field;
import java.util.Scanner;

public
class Demo2 {
    public static void setProperty(Object o, Object o1){
        try {
            Class c=o.getClass();
            Field[] f=c.getDeclaredFields();


            Class c1=o1.getClass();
            Field[] f1= c1.getDeclaredFields();
            for (Field m1:f){
                for (Field m2:f1){
                    if(m1.getType()==m2.getType()&&m1.getName()==m2.getName()){
                        m2.set(o1,m1.get(o));
                    }
                }
            }
        } catch (IllegalAccessException e){
            e.printStackTrace();
        }
    }
    public static
    void main(String[] args) {
        D2 d2=new D2("罗浩",18,"学生");
        DD2 dd2=new DD2();
        Scanner sc=new Scanner(System.in);
        setProperty(d2,dd2);
        setProperty(d2,dd2);
        System.out.println("dd2类："+dd2.name+"\t"+dd2.age+"\t"+dd2.sex+"\n"+"d2类："+d2.name+"\t"+d2.age+"\t"+d2.type);
    }
}
class D2{
    String name;
    Integer age;
    String type;
    public D2(String name,Integer age,String type){
        this.name=name;
        this.age=age;
        this.type=type;
    }
}
class DD2{
    String name;
    Integer age;
    String sex;

}